//! $Id$
//!
//! @File    Configuration.h
//! @Author  Johan Andersson <skagget77@gmail.com>
//! @Date    Thu Oct 01 20:21 2009
//! @Ingroup IoCpp

#if !defined(IOCPP_CONFIGURATION_H)
#define IOCPP_CONFIGURATION_H

#include "IoCpp/Injector.h"
#include "IoCpp/Detail/BindValueContext.h"
#include "IoCpp/Detail/ContextCommit.h"
#include "IoCpp/Detail/Resolver.h"
#include "IoCpp/Detail/ValueContext.h"

#include <boost/shared_ptr.hpp>
#include <string>

namespace IoCpp
{
   //!
   //! @author  Johan Andersson <skagget77@gmail.com>
   //! @date    Thu Oct 01 20:21 2009
   //! @ingroup IoCpp
   //!
   //! The Configuration class.
   //!
   class IOCPP_API Configuration 
   {
   public :
      //!
      //! Creates a new instance of the Configuration class.
      //!
      //! @param resolver The container's Resolver.
      //!
      Configuration( Detail::Resolver& resolver );

      //!
      //! Binds a value to the configuration.
      //!
      //! @return A BindValueContext instance.
      //!
      template<class T1>
      Detail::BindValueContext<T1> BindValue();

      //!
      //! Binds a named value to the configuration.
      //!
      //! @param  withName The name of the bound value.
      //!
      //! @return A BindValueContext instance.
      //!
      template<class T1>
      Detail::BindValueContext<T1> BindValue( const std::string& withName );

   private :
      Detail::Resolver& resolver;
   };


   template<class T1>
   Detail::BindValueContext<T1> Configuration::BindValue() {
      return BindValue<T1>("");
   }


   template<class T1>
   Detail::BindValueContext<T1> Configuration::BindValue( const std::string& withName ) 
   {
      Detail::ContextCommit<Detail::ValueContext<T1> > commit(resolver.GetCache());

      return Detail::BindValueContext<T1>(boost::shared_ptr<Detail::ValueContext<T1> >(
         new Detail::ValueContext<T1>(resolver.GetInjector(), withName), commit)
      );
   }
}

#endif   // IOCPP_CONFIGURATION_H
